package com.liu.frame.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

/**
 * Created by 刘智强 on 2016/10/26.
 * 获取APP相关信息的工具类
 */

public class AppUtils {
    /**
     2  * 获取版本号String
     3  * @return 当前应用的版本号
     4  */
    //版本号
    public static String getVersionCode(Context context) {
        return getPackageInfo(context).versionName+"";
    }

    private static PackageInfo getPackageInfo(Context context) {
        PackageInfo pi = null;

        try {
            PackageManager pm = context.getPackageManager();
            pi = pm.getPackageInfo(context.getPackageName(),
                    PackageManager.GET_CONFIGURATIONS);

            return pi;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return pi;
    }
}
